package com.webapp.controller;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.webapp.model.CommentModel;
import com.webapp.model.PostModel;

/**
 * Servlet implementation class Dislike
 */
public class Dislike extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public Dislike() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String postid = request.getParameter("POSTID");
		String commentid = request.getParameter("COMMENTID");
		int userid = Integer.parseInt((String)request.getParameter("USERID"));
		
		
		if (postid != null) {
			int postID = Integer.parseInt((String)postid);
			PostModel pm = new PostModel();
			if(pm.unlikePost(postID, userid)) {
				System.out.println("EMPTY SO LIKE");
				response.sendRedirect("Circles.do");
			}  else {
				response.sendRedirect("Error.jsp");
			}
		} else  if(commentid != null){
			int commentID = Integer.parseInt((String)commentid);
			CommentModel cm = new CommentModel();
			System.out.print("DONE");
			if(cm.unlikeComment(userid, commentID)) {
				response.sendRedirect("Circles.do");
			} else {
				response.sendRedirect("Error.jsp");
			}
		}
		
		
	}

}
